/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package bmacotada.orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import bmacotada.orm.*;

public class Pregunta_1DAOImpl implements bmacotada.orm.dao.Pregunta_1DAO {
	public Pregunta_1 loadPregunta_1ByORMID(int pr_id_pregunta) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPregunta_1ByORMID(session, pr_id_pregunta);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 getPregunta_1ByORMID(int pr_id_pregunta) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getPregunta_1ByORMID(session, pr_id_pregunta);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByORMID(int pr_id_pregunta, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPregunta_1ByORMID(session, pr_id_pregunta, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 getPregunta_1ByORMID(int pr_id_pregunta, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getPregunta_1ByORMID(session, pr_id_pregunta, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByORMID(PersistentSession session, int pr_id_pregunta) throws PersistentException {
		try {
			return (Pregunta_1) session.load(bmacotada.orm.Pregunta_1.class, new Integer(pr_id_pregunta));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 getPregunta_1ByORMID(PersistentSession session, int pr_id_pregunta) throws PersistentException {
		try {
			return (Pregunta_1) session.get(bmacotada.orm.Pregunta_1.class, new Integer(pr_id_pregunta));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByORMID(PersistentSession session, int pr_id_pregunta, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pregunta_1) session.load(bmacotada.orm.Pregunta_1.class, new Integer(pr_id_pregunta), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 getPregunta_1ByORMID(PersistentSession session, int pr_id_pregunta, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pregunta_1) session.get(bmacotada.orm.Pregunta_1.class, new Integer(pr_id_pregunta), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1[] listPregunta_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listPregunta_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1[] listPregunta_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listPregunta_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1[] listPregunta_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Pregunta_1 as Pregunta_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Pregunta_1[]) list.toArray(new Pregunta_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1[] listPregunta_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Pregunta_1 as Pregunta_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Pregunta_1[]) list.toArray(new Pregunta_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPregunta_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPregunta_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Pregunta_1[] pregunta_1s = listPregunta_1ByQuery(session, condition, orderBy);
		if (pregunta_1s != null && pregunta_1s.length > 0)
			return pregunta_1s[0];
		else
			return null;
	}
	
	public Pregunta_1 loadPregunta_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Pregunta_1[] pregunta_1s = listPregunta_1ByQuery(session, condition, orderBy, lockMode);
		if (pregunta_1s != null && pregunta_1s.length > 0)
			return pregunta_1s[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePregunta_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iteratePregunta_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePregunta_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iteratePregunta_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePregunta_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Pregunta_1 as Pregunta_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePregunta_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Pregunta_1 as Pregunta_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 createPregunta_1() {
		return new bmacotada.orm.Pregunta_1();
	}
	
	public boolean save(bmacotada.orm.Pregunta_1 pregunta_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().saveObject(pregunta_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(bmacotada.orm.Pregunta_1 pregunta_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().deleteObject(pregunta_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Pregunta_1 pregunta_1)throws PersistentException {
		try {
			bmacotada.orm.Cuestionario_1[] lCuestionario_1Cu_id_cuestionarios = pregunta_1.cuestionario_1Cu_id_cuestionario.toArray();
			for(int i = 0; i < lCuestionario_1Cu_id_cuestionarios.length; i++) {
				lCuestionario_1Cu_id_cuestionarios[i].pregunta_1Pr_id_pregunta.remove(pregunta_1);
			}
			bmacotada.orm.Respuesta_1[] lRespuesta_1s = pregunta_1.respuesta_1.toArray();
			for(int i = 0; i < lRespuesta_1s.length; i++) {
				lRespuesta_1s[i].setPregunta_1Pr_id_pregunta(null);
			}
			return delete(pregunta_1);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Pregunta_1 pregunta_1, org.orm.PersistentSession session)throws PersistentException {
		try {
			bmacotada.orm.Cuestionario_1[] lCuestionario_1Cu_id_cuestionarios = pregunta_1.cuestionario_1Cu_id_cuestionario.toArray();
			for(int i = 0; i < lCuestionario_1Cu_id_cuestionarios.length; i++) {
				lCuestionario_1Cu_id_cuestionarios[i].pregunta_1Pr_id_pregunta.remove(pregunta_1);
			}
			bmacotada.orm.Respuesta_1[] lRespuesta_1s = pregunta_1.respuesta_1.toArray();
			for(int i = 0; i < lRespuesta_1s.length; i++) {
				lRespuesta_1s[i].setPregunta_1Pr_id_pregunta(null);
			}
			try {
				session.delete(pregunta_1);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(bmacotada.orm.Pregunta_1 pregunta_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().refresh(pregunta_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(bmacotada.orm.Pregunta_1 pregunta_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().evict(pregunta_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pregunta_1 loadPregunta_1ByCriteria(Pregunta_1Criteria pregunta_1Criteria) {
		Pregunta_1[] pregunta_1s = listPregunta_1ByCriteria(pregunta_1Criteria);
		if(pregunta_1s == null || pregunta_1s.length == 0) {
			return null;
		}
		return pregunta_1s[0];
	}
	
	public Pregunta_1[] listPregunta_1ByCriteria(Pregunta_1Criteria pregunta_1Criteria) {
		return pregunta_1Criteria.listPregunta_1();
	}
}
